<?php

class PackageCreator
{
    protected static $base = null;
    
    public function travelDir( $directory )
    {
        if ( self::$base === null )
            self::$base = $directory;
        foreach( scandir( $directory ) as $entries )
        {
            if( $entries[0] == '.' )
                continue;
            else if( is_dir( $directory.DIRECTORY_SEPARATOR.$entries ) )
                $this->travelDir( $directory.DIRECTORY_SEPARATOR.$entries, $this->fp );
            else if ( is_file( $directory.DIRECTORY_SEPARATOR.$entries ) )
            {
                fwrite( $this->fp, "<file md5sum='".md5_file( $directory.DIRECTORY_SEPARATOR.$entries )."' name='".str_replace( self::$base, "", $directory.DIRECTORY_SEPARATOR.$entries )."' role='data' />\n" );
            }
        }
    }
    
    public function __construct( $dir )
    {
        $this->fp = fopen( 'grep.txt', 'w' );
        $this->travelDir( $dir );
    }
}

$a = new PackageCreator( getcwd() );
?>